package com.crm.controller;

import com.crm.dto.FollowDto;
import com.crm.entity.ClueRecord;
import com.crm.result.PageResultTow;
import com.crm.result.Result;
import com.crm.service.FollowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 跟进相关接口
 */
@RestController
public class FollowController {
    @Autowired
    private FollowService followService;
    @PostMapping("/clues/record")
    public Result insertFollow(@RequestBody FollowDto followDto){
        followService.insertFollow(followDto);
        return Result.success();
    }
    /**
     * http://localhost:8888/api/clues/record/list?clueId=6
     * 查询对应跟进表信息
     */
    @GetMapping("/clues/record/list")
    public PageResultTow getClueRecords(@RequestParam("clueId") Long clueId){
        PageResultTow recordsByClueId = followService.getRecordsByClueId(clueId);
        return recordsByClueId;
    }



    /**
     * 转商机
     */
    @PutMapping("/clues/clue/changeBusiness/{id}")
    public Result putBusiness(@PathVariable Long id){
        followService.putBusiness(id);
        return Result.success();
    }

    /**
     * http://localhost:8888/api/clues/clue/false/6
     * 上报伪线索
     */
    @PutMapping("/clues/clue/false/{id}")
    public Result putFake(@PathVariable Long id, @RequestBody Map<String,String> payload){
        String reason = payload.get("reason");
        String remark = payload.get("remark");
//        System.out.println(id+" "+reason+" "+remark);
        followService.hanleFakeClue(id,reason,remark);


        return Result.success();
    }
}
